/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * The software in this package is published under the terms of the GPL v2.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE-GPL.txt file.
 */

package org.cemantika.model;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.cemantika.contextsource.ContextSourceAdapter;

/**
 * ContextSource represents a context source with contextual element is updated according to the
 * context source adapter.
 * 
 * @author andersonfellipe
 */
@SuppressWarnings("unchecked")
public class ContextSourceModel {

    /**
     * Represents the context source adapter.
     */
    private ContextSourceAdapter contextSourceAdapter;
    /**
     * Represents the element key of the contextual element.
     */
    private String element;
    /**
     * Represents the type of the context source.
     */
    private String contextSourceType;

    /**
     * Creates a new instance of ContextSource.
     */
    public ContextSourceModel(ContextSourceAdapter contextSourceAdapter, String element, String contextSourceType) {
        this.contextSourceAdapter = contextSourceAdapter;
        this.element = element;
        this.contextSourceType = contextSourceType;
    }

    /**
     * Creates a new instance of ContextSource.
     */
    public ContextSourceModel(ContextSourceAdapter contextSourceAdapter) {
        this.contextSourceAdapter = contextSourceAdapter;
    }

    /**
     * Returns the context source related to this {@link ContextSourceAdapter}.
     * 
     * @return the object of the context source.
     */
    public Object getContextSource() {
        return contextSourceAdapter.getContextSource();
    }

    /**
     * Get the contextSourceAdapter value.
     * 
     * @return the contextSourceAdapter.
     */
    public ContextSourceAdapter getContextSourceAdapter() {
        return contextSourceAdapter;
    }

    /**
     * Get the element value.
     * 
     * @return the element.
     */
    public String getElement() {
        return element;
    }

    /**
     * Get the contextSourceType value.
     * 
     * @return the contextSourceType.
     */
    public String getContextSourceType() {
        return contextSourceType;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof ContextSourceModel)) {
            return false;
        }
        ContextSourceModel other = (ContextSourceModel) obj;
        return new EqualsBuilder().append(contextSourceAdapter, other.contextSourceAdapter).isEquals();
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        return new HashCodeBuilder(-806458195, -1310850617).append(contextSourceAdapter).toHashCode();
    }

}
